#!/bin/sh
echo "Running quality tests"
echo "====================="

# Si se han pasado argumentos, se emplearán para acceder al agente indicado:
# sintaxis: ./run.sh [IP] [PUERTO] [USUARIO] [PASS]
if test -z "$1"; then 
	IP="127.0.0.1"
else
	IP="$1"
fi
if test -z "$2"; then
	PORT="8001"
else
	PORT="$2"
fi
if test -z "$3"; then
	USER="admin"
else
	USER="$3"
fi
if test -z "$4"; then
	PASS="opendomo"
else
	PASS="$4"
fi

# Iteramos para cada subdirectorio
for i in *; do
	if test -d $i; then
		cd $i
		if test -x run.sh; then
			if ! ./run.sh $IP $PORT $USER $PASS
			then
				echo "FAILED"
				exit 1
				# Abortamos al primer fallo
			fi
		fi
		if test -x run.py; then
			if ! ./run.py $IP $PORT $USER $PASS
			then
				echo "FAILED"
				exit 1
				# Abortamos al primer fallo
			fi
		fi
		cd ..
	fi
done

echo "Tests successful!"
echo
